﻿<UserControl x:Class="ScrumFactory.Team.RolesList"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:props="clr-namespace:ScrumFactory.Team.Properties"
             xmlns:SF="clr-namespace:ScrumFactory;assembly=ScrumFactory"             
             xmlns:SF_Helpers="clr-namespace:ScrumFactory.Windows.Helpers;assembly=ScrumFactory.Windows.Helpers"
             xmlns:KExt="clr-namespace:System.Windows.KExtensions;assembly=System.Windows.KExtensions"
             
             x:Name="thisView"
             mc:Ignorable="d"              
             d:DesignHeight="500" d:DesignWidth="600">

    <TabControl Style="{StaticResource WindowTabControl}">
        <TabControl.Items>
            <TabItem Header="{Binding PanelName}">
                <SF_Helpers:PanelLayout Title="{Binding PanelName}" Style="{StaticResource DetailPanelLayout}">

                    <!-- TOOLBAR -->
                    <SF_Helpers:PanelLayout.Toolbar>
                        <ToolBar>
                            <MenuItem Style="{StaticResource GoBackMenuItem}"/>
                            <MenuItem     
                                x:Name="newRoleMenuItem"
                                Header="{x:Static props:Resources.Add_new_role}" Command="{Binding AddNewRoleCommand}">
                                <MenuItem.Icon>
                                    <Image Source="/Images/ToolBar/add.png" Width="32" Height="32" Stretch="Uniform"/>
                                </MenuItem.Icon>
                            </MenuItem>
                        </ToolBar>
                    </SF_Helpers:PanelLayout.Toolbar>

                    <!-- CONTENT -->
                    <SF_Helpers:PanelLayout.Content>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>

                            <ListBox
                        x:Name="list"
                        Grid.Column="0"                
                        Width="250"
                        IsSynchronizedWithCurrentItem="True"
                        Background="Transparent"
                        BorderThickness="0"
                        SelectedItem="{Binding SelectedRole}"                        
                        ItemsSource="{Binding Roles}">
                                <ListBox.ItemTemplate>
                                    <DataTemplate>
                                        <Grid>
                                            <StackPanel Orientation="Horizontal" x:Name="panel">
                                                <Image Source="/Images/role.png" VerticalAlignment="Top" Stretch="Uniform" Width="32" Height="32" Margin="5"/>

                                                <TextBlock >
                                        <TextBlock
                                        Style="{StaticResource ItemTitleTextBlock}"
                                        Text="{Binding Role.RoleName}"/>                                        
                                        <LineBreak/>
                                        <TextBlock
                                            Width="200" TextWrapping="Wrap" TextTrimming="CharacterEllipsis" MaxHeight="60"                                        
                                            Text="{Binding Role.RoleDescription}"/>                                        
                                    </TextBlock>

                                            </StackPanel>

                                            <DockPanel Style="{StaticResource ItemActionMenu}">
                                                <Button                                
                                        Style="{StaticResource RemoveActionButton}"                                                                   
                                        Command="{Binding ElementName=list, Path=DataContext.DeleteRoleCommand}"
                                        CommandParameter="{Binding}"/>
                                            </DockPanel>



                                        </Grid>
                                    </DataTemplate>
                                </ListBox.ItemTemplate>
                            </ListBox>

                            <Grid Grid.Column="1" DataContext="{Binding ElementName=list, Path=SelectedItem}" Margin="10,0,0,0" >
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="*" />
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="Auto"/>
                                </Grid.RowDefinitions>
                                <TextBlock 
                            Grid.Column="0" Grid.Row="0"                            
                            Style="{StaticResource LabelTextBlock}"
                            Text="{x:Static props:Resources.Role_name}"/>
                                <TextBox
                            Grid.Column="1" Grid.Row="0"                        
                            HorizontalAlignment="Stretch" MaxLength="50"
                            Text="{Binding Role.RoleName, UpdateSourceTrigger=PropertyChanged}"/>
                                <TextBlock 
                            Grid.Column="0" Grid.Row="1"                            
                            Style="{StaticResource LabelTextBlock}"
                            Text="{x:Static props:Resources.Role_short_name}"/>
                                <TextBox
                            Grid.Column="1" Grid.Row="1"                        
                            HorizontalAlignment="Stretch" MaxLength="15"
                            Text="{Binding Role.RoleShortName, UpdateSourceTrigger=PropertyChanged}"/>
                                <TextBlock 
                            Grid.Column="0" Grid.Row="2"                            
                            Style="{StaticResource LabelTextBlock}"
                            Text="{x:Static props:Resources.Permission}"/>
                                <ComboBox
                                Grid.Column="1" Grid.Row="2"
                                SelectedValue="{Binding Role.PermissionSet, Converter={StaticResource EnumToShortConverter}, ConverterParameter={x:Type SF:PermissionSets}, UpdateSourceTrigger=PropertyChanged}"   
                                ItemsSource="{Binding Source={StaticResource PermissionList}}">
                                    <ComboBox.ItemTemplate>
                                        <DataTemplate>
                                            <Grid>
                                                <Image DataContext="{Binding}" Style="{StaticResource PermissionSetImage}" Width="20" Height="20" Stretch="Uniform" HorizontalAlignment="Left"/>
                                                <TextBlock Margin="25,0,0,0" Text="{Binding ., Converter={StaticResource LocalizeConverter}}"/>
                                            </Grid>
                                        </DataTemplate>
                                    </ComboBox.ItemTemplate>
                                </ComboBox>

                                <TextBlock 
                            Grid.Column="0" Grid.Row="3"
                            VerticalAlignment="Top"
                            Style="{StaticResource LabelTextBlock}"
                            Text="{x:Static props:Resources.Description}"/>
                                <TextBox
                                    KExt:SpellCheck.IsEnabled="True"
                            Grid.Column="1" Grid.Row="3"                        
                            HorizontalAlignment="Stretch" Height="100" MaxLength="255"
                            ScrollViewer.VerticalScrollBarVisibility="Auto"
                            TextWrapping="Wrap"                            
                            Text="{Binding Role.RoleDescription, UpdateSourceTrigger=PropertyChanged}"/>

                                <CheckBox Grid.Column="1" Grid.Row="4" IsChecked="{Binding IsDefaultRole}" >
                                    <CheckBox.Content>
                                        <TextBlock>
                                            <Run Foreground="{StaticResource LabelBrush}" Text="{x:Static props:Resources.Default_role}"/><LineBreak/>
                                            <Run Foreground="{StaticResource SubTextBrush}" Text="{x:Static props:Resources.Default_role_tooltip}"/>                                            
                                        </TextBlock>                                        
                                    </CheckBox.Content>
                                </CheckBox>


                            </Grid>



                        </Grid>
                    </SF_Helpers:PanelLayout.Content>
                </SF_Helpers:PanelLayout>
            </TabItem>
        </TabControl.Items>
    </TabControl>
    
</UserControl>
